package org.example.service.impl;

import cn.hutool.crypto.digest.DigestUtil;
import org.example.config.R;
import org.example.domain.Param;
import org.example.mapper.ParamMapper;
import org.example.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParamServiceImpl implements ParamService {
    @Autowired
    ParamMapper paramMapper;
    @Override
    public List<Param> list(Param param) {
      List<Param> list=  paramMapper.list(param);
        return list;
    }

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public R add(Param param) {
        String key= DigestUtil.md5Hex(param.toString());
        if(!redisTemplate.hasKey(key)){
            paramMapper.add(param);
            return R.successed(null);
        }else{
            return R.failed("禁止重复添加");
        }
    }

    @Override
    public void delByUpdate(Integer id) {
        paramMapper.delByUpdate(id);
    }

    @Override
    public void updates(Param param) {
        paramMapper.updates(param);

    }

    @Override
    public List<Param> lists() {
       List<Param> list= paramMapper.lists();
        return list;
    }

    @Override
    public void delAll(Integer[] ids) {
        paramMapper.dellAll(ids);
    }

    @Override
    public Param getById(Integer id) {
        Param param=paramMapper.getById(id);
        return param;
    }


}
